package com.wgts.wgts.control.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.localbean.JoinPeopleData;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/*
 *
 *
 *   data:2018/10/1619:58
 *
 */public class JoinPeopleAdapter extends RecyclerView.Adapter<JoinPeopleAdapter.ViewHold> {
    private Context context;
    private List<JoinPeopleData> list;

    public JoinPeopleAdapter(Context context, List<JoinPeopleData> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.join_people_recycle_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        if (i % 2 != 0) {
            viewHold.joinPeopleItemLy.setBackgroundColor(ContextCompat.getColor(context, R.color.whrite));
        }else{
            viewHold.joinPeopleItemLy.setBackgroundColor(ContextCompat.getColor(context, R.color.app_bg));
        }
        MoHuGlide.getInstance().glideImg(context, list.get(i).userHeadImag, viewHold.image);
        viewHold.name.setText(list.get(i).name);
        if(!list.get(i).price.equals("0")){
            viewHold.price.setText(list.get(i).price);
        }else{
            viewHold.price.setText("");
        }
        viewHold.time.setText(list.get(i).time);
        if (viewHold.status.equals("")) {
            viewHold.status.setText("");
        } else {
            viewHold.status.setText(list.get(i).status);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.join_people_item_ly)
        RelativeLayout joinPeopleItemLy;
        @BindView(R.id.image)
        CircleImageView image;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.status)
        TextView status;
        @BindView(R.id.price)
        TextView price;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
